package com.company.psm.serviceimpl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.company.psm.entity.Store;
import com.company.psm.genericdao.CustomGenericDAO;
import com.company.psm.service.StoreManagement;

@Service(value="storeManagement")
@Transactional(readOnly = true, propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
public class StoreManagementImpl  extends CustomGenericDAO<Object> implements StoreManagement {

	public List<Store> getAll() {
		return _all(Store.class);
	}
	@Transactional(readOnly = false)
	public void update(String userId, String name, String address,
			String phoneNum, String status) {
		Store store = _get(Store.class, Long.parseLong(userId));
		store.setStoreName(name);
		store.setAddress(address);
		store.setPhoneNumber(phoneNum);
		store.setStatus(status);
		_update(store);
		
	}
	@Transactional(readOnly = false)
	public void add(String name, String address, String phoneNum, String status) {
		Store store = new Store();
		store.setStoreName(name);
		store.setAddress(address);
		store.setPhoneNumber(phoneNum);
		store.setStatus(status);
		_save(store);
	}

	public List<Store> search(String name) {
		// TODO Auto-generated method stub
		return null;
	}

	public void delete(long storeId) {
		// TODO Auto-generated method stub
		
	}

	public Store getStoreById(long storeId) {
		// TODO Auto-generated method stub
		Store result = new Store();
		List<Store> storeList = this.getAll();
		for (Store store : storeList) {
			if(store.getId() == storeId)
			{
				result = store;
			}
		}
		return result;
	}
	public Object find(Long id) {
		// TODO Auto-generated method stub
		return null;
	}
	public Object[] find(Long... ids) {
		// TODO Auto-generated method stub
		return null;
	}
	public Object getReference(Long id) {
		// TODO Auto-generated method stub
		return null;
	}
	public Object[] getReferences(Long... ids) {
		// TODO Auto-generated method stub
		return null;
	}
	public boolean removeById(Long id) {
		// TODO Auto-generated method stub
		return false;
	}
	public void removeByIds(Long... ids) {
		// TODO Auto-generated method stub
		
	}
	public Store getStoreByName(String name) {
		// TODO Auto-generated method stub
		Store result = new Store();
		List<Store> storeList = this.getAll();
		for (Store store : storeList) {
			if(store.getStoreName().equals(name)){
				result = store;
			}
		}
		return result;
	}

}
